import 'package:enjoy_plus/pages/house/house_list.dart';
import 'package:enjoy_plus/pages/login/index.dart';
import 'package:enjoy_plus/pages/notice/index.dart';
import 'package:enjoy_plus/pages/profile/index.dart';
import 'package:enjoy_plus/pages/tab_bar_page.dart';
import 'package:enjoy_plus/utils/token.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      routes: {
        '/': (context) => const TabBarPage(),
        '/detail': (context) => const NoticeDetail(),
        '/login': (context) => const LoginPage(),
        // "detail": (context) => const ProfilePage()
      },
      initialRoute: '/',
      onGenerateRoute: (settings) {
        // 获取 token
        final token = TokenManager().getToken();
        // 如果 token 为空，跳转到登录页
        if (token == null) {
          return MaterialPageRoute(builder: (context) => const LoginPage());
        } else if (settings.name == '/profile') {
          print("当前传递参数:${settings.arguments}");
          return MaterialPageRoute(builder: (context) {
            return ProfilePage(userInfo: settings.arguments as Map);
          });
        }
        if (settings.name == '/house_list') {
          return MaterialPageRoute(builder: (context) => const HouseList());
        }

        return null;
      },
    ),
  );
}
